//
//  JLCFHttpManager.h
//  QTZ
//
//  Created by ski on 2017/7/6.
//  Copyright © 2017年 ski. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AFNetworking.h"

typedef void(^SuccessBlock)(NSDictionary *result);
typedef void(^FailureBlock)(NSString *status);
typedef void(^HeaderBlock)(NSDictionary *header);

/**
 *  http 请求公用类，默认请求地址为 apihost + apiPath + path, 如果需要使用别的地址请继承 XSJRequest，重写 init 方法
 */
@interface JLCFHttpManager : NSObject {
    AFHTTPRequestOperationManager *_httpManager;
}


/**
 *  网络状态
 */
@property (nonatomic, assign) AFNetworkReachabilityStatus networkStatus;

/**
 *  是否在 wifi 环境
 */
@property (nonatomic, assign) BOOL isUnderWifi;

/**
 *  单例方法
 *
 *  @return XSJRequest 实例
 */
+ (instancetype)sharedManager;

/**
 *  拼接系统参数
 *
 *  @param params 接口的参数字典
 *
 *  @return 拼接后的参数字典
 */
+ (NSMutableDictionary *)generateSystemParamsWithApiParams:(NSDictionary *)params;


/**
 *  设置调试模式，即请求 json 格式数据
 *
 *  @param debugMode 是否调试模式
 */
+ (void)setDebugMode:(BOOL)debugMode;

/**
 *  开始监听网络状态
 */
+ (void)startMonitoringNetworkStatus;



/**
 *  get 方法请求接口
 *
 *  @param url    接口路径
 *  @param params  参数
 *  @param view    需要加 loading 的 view
 *  @param success success block
 *  @param failure failure block
 */
- (void)getDataWithUrl:(NSString *)url
                params:(NSDictionary *)params
         loadingInView:(UIView *)view
               success:(void (^)(NSDictionary *result))success
               failure:(void (^)(NSString *status))failure;

/**
 *  post 方法请求接口
 *
 *  @param url    接口路径
 *  @param params  参数
 *  @param view    需要加 loading 的 view
 *  @param success success block
 *  @param failure failure block
 */
- (void)postDataWithUrl:(NSString *)url
                 params:(NSDictionary *)params
          loadingInView:(UIView *)view
                success:(void (^)(NSDictionary *result))success
                failure:(void (^)(NSString *status))failure;

/**
 *  http方法请求接口
 *
 *  @param url        接口路径
 *  @param params     参数
 *  @param method     方法
 *  @param view       需要加 loading 的 view
 *  @param success    success block
 *  @param failure    failure block
 *  @param loginCheck 当登录无效时候是否弹出login框
 */
- (void)requestWithUrl:(NSString *)url
                params:(NSDictionary *)params
                method:(NSString *)method
                  view:(UIView *)view
               success:(SuccessBlock)success
               failure:(FailureBlock)failure
            loginCheck:(BOOL)loginCheck;

//带header的http请求

//- (void)requestWithUrl:(NSString *)url
//                params:(NSDictionary *)params
//                method:(NSString *)method
//                  view:(UIView *)view
//               success:(SuccessBlock)success
//               failure:(FailureBlock)failure
//             header:(HeaderBlock)header;

/**
 *  用于发表的post方法
 */
- (AFHTTPRequestOperation *)postWithManager:(AFHTTPRequestOperationManager *)manager
                                        url:(NSString *)url
                                     params:(NSDictionary *)params
                  constructingBodyWithBlock:(void(^)(id<AFMultipartFormData> formData))constructingBlock
                              loadingInView:(UIView *)view
                                    success:(void (^)(NSDictionary *result))success
                                    failure:(void (^)(NSString *status))failure;
/**
 *  发送 MultipartFormData 类型数据（图片、文件等）
 *
 *  @param url              接口路径
 *  @param params            参数（拼接在 url 中）
 *  @param constructingBlock 拼接 httpbody 的 block
 *  @param view              需要加 loading 的 view
 *  @param success           success block
 *  @param failure           failure block
 */
- (void)postMultipartFormDataWithUrl:(NSString *)url
                              params:(NSDictionary *)params
           constructingBodyWithBlock:(void(^)(id<AFMultipartFormData> formData))constructingBlock
                       loadingInView:(UIView *)view
                             success:(void (^)(NSDictionary *result))success
                             failure:(void (^)(NSString *status))failure;

/**
 *  取消指定接口的请求
 *
 *  @param url 接口路径
 */
- (void)cancelGetRequestWithUrl:(NSString *)url ;


@end
